Add missing POST /ingredicheck/v2/scan/{scanId}/image endpoint#17
Add missing POST /ingredicheck/v2/scan/{scanId}/image endpoint#17iAmVishal16 wants to merge 1 commit intomainfrom
Conversation
iAmVishal16
commented
Dec 24, 2025
- Add uploadImage function to scan.ts
- Handle form-data image uploads
- Generate SHA-256 content hash for deduplication
- Upload images to scan-images storage bucket
- Create scan_images records with pending status
- Register route in index.ts
- Add uploadImage function to scan.ts - Handle form-data image uploads - Generate SHA-256 content hash for deduplication - Upload images to scan-images storage bucket - Create scan_images records with pending status - Register route in index.ts
Pull Request Review: Add POST /ingredicheck/v2/scan/{scanId}/image endpointI've thoroughly reviewed this PR against the codebase patterns, security requirements, and database schema. Here's my detailed feedback: ✅ Strengths1. Excellent Security Implementation
2. Robust Error Handling
3. Smart Duplicate Detection
4. Proper Activity Tracking
5. Follows Established Patterns
|
| Category | Rating | Notes |
|---|---|---|
| Authentication | ✅ GOOD | JWT verified by middleware |
| Authorization | ✅ GOOD | RLS enforces ownership |
| Input Validation | Missing UUID, content-type validation | |
| File Upload | ✅ GOOD | Size limits, content hashing, safe paths |
| Error Handling | ✅ GOOD | Generic messages, proper cleanup |
| Injection Risks | ✅ GOOD | Parameterized queries, UUID paths |
| Rate Limiting | ❌ MISSING | No rate limit (contrast: memoji has it) |
Recommendation: Add rate limiting to prevent abuse:
// Example: limit 20 uploads per scan per minute
// Could use Redis or database-based rate limiting📝 Code Quality
✅ Excellent
- Clear function names (
uploadImage,generateContentHash) - Consistent code style with codebase
- Good separation of concerns
- Proper TypeScript types
⚠️ Minor Issues
- Magic number
10for MB limit anytype for imageFile (scan.ts:348):formData.files?.find((file: any) => ...)- Recommendation: Define proper type or use
unknown
- Recommendation: Define proper type or use
🎯 Test Coverage Needed
Based on feedback.ts testing patterns, add:
// test/scan-upload.test.ts
Deno.test('POST /scan/{id}/image - success', async () => { ... })
Deno.test('POST /scan/{id}/image - duplicate', async () => { ... })
Deno.test('POST /scan/{id}/image - invalid UUID', async () => { ... })
Deno.test('POST /scan/{id}/image - unauthorized', async () => { ... })📋 Checklist for Approval
Must Fix (CRITICAL)
- Add UUID validation for
scanId
Should Fix (MEDIUM)
- Add content-type validation (JPEG, PNG, WebP only)
- Fix hardcoded
.jpgextension based on actual content type - Consider stricter file size limit (5MB instead of 10MB)
Nice to Have (LOW)
- Add test coverage
- Add API documentation
- Define
MAX_IMAGE_SIZE_MBconstant - Add rate limiting
- Handle UNIQUE constraint race condition explicitly
- Add image dimension validation
🏁 Overall Assessment
Rating: 7.5/10 - Good implementation with room for improvement
Strengths:
- Excellent security foundation (RLS, ownership checks, cleanup)
- Follows codebase patterns consistently
- Smart duplicate detection
- Proper error handling structure
Weaknesses:
- Missing input validation (UUID, content-type)
- No test coverage
- No rate limiting
Recommendation: APPROVE with changes - Fix the critical UUID validation issue and medium-priority content-type validation before merging. Other suggestions can be addressed in follow-up PRs.
Great work on implementing this endpoint! The core logic is solid, and with a few validation improvements, this will be production-ready. Let me know if you need any clarification on these recommendations.